home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
clang
/
tcplusx.zip
/
CURSOR.CPP
next >
Wrap
C/C++ Source or Header
|
1991-02-28
|
6KB
|
223 lines
//
// cursor.cpp - implementation for class Cursor
// Author - Robin W. McKean
// Last Update - February 23,1991
// Copyright (C) 1991 All rights reserved
//
// This file remains the property of the author, Robin W. McKean. You are
// free to use and change it as you see fit. This module, nor its object
// code, may not however be included in any packaged software without the
// written consent of the author.
//
// Contents ----------------------------------------------------------------
//
// Cursor::Cursor
// Cursor::isA
// Cursor::nameOf
// Cursor::processA
// Cursor::pollDevice
//
// Description
//
// Defines the class Cursor. The purpose of this class is to allow
// the cursor to be used as an ordinary device. Not for input, but to
// moved around and transformed by objects through events
//
// End ---------------------------------------------------------------------
// Interface dependencies --------------------------------------------------
#ifndef _IOSTREAM_H
#include <iostream.h>
#endif
#ifndef _USETYPES_H
#include <usetypes.h>
#endif
#ifndef _GEN_H
#include <gen.h>
#endif
#ifndef _EVENT_H
#include <event.h>
#endif
#ifndef _CURSOR_H
#include <cursor.h>
#endif
// End Interface dependencies ----------------------------------------------
// Implementation dependencies ---------------------------------------------
#ifndef _DOS_H
#define _DOS_H
#include <dos.h>
#endif
#ifndef _CONIO_H
#define _CONIO_H
#include <conio.h>
#endif
// End Implementation dependencies -----------------------------------------
// Member Function //
Cursor::Cursor( int initStatus ) : Device( initStatus )
// Summary ------------------------------------------------------------------
//
// Sets the initial status of the cursor. It saves some of the defaults
// of the cursor, so they can be restored when this object is destroyed
//
// End ---------------------------------------------------------------------
{
REGS regs;
// Set the device type
type = D_CURSOR;
// Read the cursor size and position, using the BIOS
regs.h.ah = 3;
regs.h.bh = 0;
int86( 0x10, ®s, ®s );
// Save the cursor size and position
initialCursorState = _NORMALCURSOR;
line = ( unsigned int ) regs.h.dh;
column = ( unsigned int ) regs.h.dl;
currentCursorState = oldCursorState = initialCursorState;
if( status == D_ON ) _setcursortype( _NORMALCURSOR );
else _setcursortype( _NOCURSOR );
}
// End Cursor::Cursor //
// Member Function //
#pragma argsused
Cursor::Cursor( Device& theDevice )
// Description -------------------------------------------------------------
//
// Copies one Cursor into another
//
// Parameters
//
// Device&
//
// The Cursor to be copied
//
// End ---------------------------------------------------------------------
{
initialCursorState = ( ( Cursor& )theDevice ).initialCursorState;
line = ( ( Cursor& )theDevice ).line;
column = ( ( Cursor& )theDevice ).column;
currentCursorState = ( ( Cursor& )theDevice ).currentCursorState;
oldCursorState = ( ( Cursor& )theDevice ).oldCursorState;
}
// End Cursor::Cursor //
// Member Function
Cursor::~Cursor( )
// Description --------------------------------------------------------------
//
// This destructor restores the normal cursor, and places the cursor
// back into the location it was when this object was created
//
// End ----------------------------------------------------------------------
{
// Restore the cursor size using the BIOS
_setcursortype( _NORMALCURSOR );
// Restore the cursor position
gotoxy( column, line );
}
// Cursor::~Cursor //
// Member Function //
classType Cursor::isA( ) const
// Description -------------------------------------------------------------
//
// Returns a value representation of a class
//
// End ---------------------------------------------------------------------
{
return cursorClass;
}
// End Cursor::isA( ) //
// Member Function //
char *Cursor::nameOf( ) const
// Description -------------------------------------------------------------
//
// Returns a character representation of a class
//
// End ---------------------------------------------------------------------
{
return "Cursor";
}
void Cursor::pollDevice( )
// Description -------------------------------------------------------------
//
// This is a stub function, since the cursor cannot return information
//
// End ---------------------------------------------------------------------
{
}
int Cursor::processA( Event& theEvent )
{
if( theEvent.type == S_DEVICE && status != D_INACTIVE )
{
switch( theEvent.typeCode )
{
case D_ON:
case D_SHOW:
if( currentCursorState != _NOCURSOR ) return( 0 );// Cursor on?
_setcursortype( oldCursorState ); // Save old
currentCursorState = oldCursorState; // Set new
break;
case D_OFF:
case D_HIDE:
if( currentCursorState == _NOCURSOR ) return( 0 );// Cursor off?
oldCursorState = currentCursorState; // Save old
_setcursortype( _NOCURSOR ); // Set new
currentCursorState = _NOCURSOR;
break;
case D_POSITION:
int x = theEvent.point.row; // Set position using
int y = theEvent.point.column; // BIOS calls
gotoxy( y, x );
break;
case DC_INSERT:
oldCursorState = currentCursorState;
_setcursortype( _NORMALCURSOR );
currentCursorState = _NORMALCURSOR;
break;
case DC_OVERTYPE:
oldCursorState = currentCursorState;
_setcursortype( _SOLIDCURSOR );
currentCursorState = _SOLIDCURSOR;
break;
}
}
return( 0 );
}